<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.vsked.util.*"%>
<%@page import="com.vsked.database.*"%>
<%@page import="com.vsked.bean.*"%>
<%@page import="com.vsked.io.*"%>
<%
    Symbol.cleanAllStaticData();
    String downloadPath=(request.getRealPath("/")+ "download/").replace("\\", "/");
    ConnectionInfo ci=(ConnectionInfo)session.getAttribute("ci");
	String inTableName = request.getParameter("tname");
	String primaryKey = request.getParameter("primaryKey").split("#")[0];
	String primaryKeyDataType = request.getParameter("primaryKey").split("#")[1];
	String[] viewArray = request.getParameterValues("isView");
	String[] addFieldNameArray = request.getParameterValues("add");
	String[] editFieldNameArray = request.getParameterValues("edit");
	
	String listJsp=JspListProcess.getListJspContent();
	String listTable="";
	String listTableHead="";
	
	String includJsp=Symbol.enterSymbol+IncludeJsp.getHeadString()+"\n<body>"+Symbol.enterSymbol+IncludeJsp.getLeftString();
	String includFootJsp=IncludeJsp.getFootString()+"\n</body>";
	
	String mStr=HtmlProcess.getTableTh("<a href='"+Symbol.getStringFirstUpperCase(inTableName)+"Servlet?method=listById&"+Symbol.getStringFirstLowerCase(primaryKey)+"=${"+Symbol.getStringFirstLowerCase(inTableName)+"."+Symbol.getStringFirstLowerCase(primaryKey)+"}"+"'>修改</a>");
	String dStr=HtmlProcess.getTableTh("<a href='javascript:void(0);' onclick='if(confirm(\"确定要删除?\"))window.location=\"../"+Symbol.getStringFirstUpperCase(inTableName)+"Servlet?method=del&delIds=${"+Symbol.getStringFirstLowerCase(inTableName)+"."+Symbol.getStringFirstLowerCase(primaryKey)+"}\";'>删除</a>");
	listTableHead=HtmlProcess.getTableTr(HtmlProcess.getJspListTableHeadTr(viewArray,request)+HtmlProcess.getTableTd("修改")+HtmlProcess.getTableTd("删除"));
	String listTableBody=HtmlProcess.getJspListTableBodyInfo(inTableName,viewArray,mStr+dStr);
	listJsp=listJsp+Symbol.enterSymbol+includJsp+Symbol.enterSymbol+"<br/><br/><br/><a href='"+Symbol.getStringFirstUpperCase(inTableName)+"Servlet?method=showadd"+"'>添加</a><br/>"+HtmlProcess.getTable(listTableHead+listTableBody);
	listJsp=listJsp+Symbol.enterSymbol+includFootJsp;
	FileOperate.delete(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"List.jsp");
	FileOperate.newFile(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"List.jsp",listJsp,"utf-8");
	session.setAttribute("listJsp",Symbol.getStringFirstUpperCase(inTableName)+"List.jsp");
	
	/*start operateJsp Content */
	String operateJsp="";
	String inOperateJspBody=HtmlProcess.getJspListTableHeadInfo(inTableName,editFieldNameArray,request,1);
	operateJsp+=JspListProcess.getAddOrEditJspContent(inTableName,HtmlProcess.getTable(inOperateJspBody+HtmlProcess.getTableTr(HtmlProcess.getTableTd(HtmlProcess.getInputSubmitButton(inTableName)+HtmlProcess.getInputResetButton()+HtmlProcess.getInputGoBackButton(),2))));
	operateJsp+=includFootJsp;
	FileOperate.deleteFile(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"Operate.jsp");
	FileOperate.newFile(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"Operate.jsp",operateJsp,"utf-8");
	session.setAttribute("operateJsp",Symbol.getStringFirstUpperCase(inTableName)+"Operate.jsp");
	
	/*start dao Content*/
	String dao=""; 
	String bean="";
	String daoContent="";
	daoContent+=DaoProcess.getDAODeclareInfo(inTableName);
	daoContent+=new DaoProcess().getAddObjectMethod(inTableName,addFieldNameArray,primaryKey,primaryKeyDataType);
	daoContent+=DaoProcess.getDelByPrimaryKeyMethod(inTableName, primaryKey,primaryKeyDataType);
	daoContent+=new DaoProcess().getEditObjectMethod(inTableName,editFieldNameArray,primaryKey,primaryKeyDataType);
	daoContent+=DaoProcess.getFindByPirmaryKeyMethod(inTableName, primaryKey,primaryKeyDataType);
	daoContent+=DaoProcess.getFindAllMethod(inTableName);
	daoContent+=DaoProcess.getFindAllMethod(inTableName,primaryKey);
	ColumnInfo.getTableColumnNameAndDataType(ci, inTableName);
	daoContent+=DaoProcess.getObjectInfo(inTableName,BeanProcess.forDAOInfoMethodString);
	dao=DaoProcess.getImportInfo()+DaoProcess.getDAO(inTableName,daoContent);
	FileOperate.delete(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"DAO.java");
	FileOperate.newFile(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"DAO.java",("".equals(request.getParameter("daoPackage"))?"":ClassProcess.getPackage(request.getParameter("daoPackage")))+("".equals(request.getParameter("beanPackage"))?"":"import "+request.getParameter("beanPackage")+".*;")+dao,"utf-8");
	session.setAttribute("dao",Symbol.getStringFirstUpperCase(inTableName)+"DAO.java");
	
	/*start bean content */
	bean=("".equals(request.getParameter("beanPackage"))?"":ClassProcess.getPackage(request.getParameter("beanPackage")))+BeanProcess.getBeanFileContent(ci, inTableName);
	FileOperate.delete(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+".java");
	FileOperate.newFile(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+".java",bean);
	session.setAttribute("bean",Symbol.getStringFirstUpperCase(inTableName)+".java");
	/*start servlet Content*/
	String jspFolder=request.getParameter("jspFolder");
    String servletAll="";
	String inServletContent="";
	inServletContent+=ServletProcess.getAddString(ServletProcess.forServletAddParmReg+Symbol.enterSymbol+ServletProcess.getDAOProcessForAddOrEdit("new "+Symbol.getStringFirstUpperCase(inTableName)+"DAO().add("+BeanProcess.getNewObjectForServlet(inTableName,BeanProcess.addNewObjectInParmForServlet)+")",ServletProcess.getSetSessionAttribute("\"result\"", "\"添加成功\""),ServletProcess.getSetSessionAttribute("\"result\"", "\"添加失败\"")),inTableName,jspFolder);
	inServletContent+=ServletProcess.getDeleteString(ServletProcess.getDAOProcessForDel("UtilDAO.delin(\""+inTableName+"\", \""+primaryKey+"\", "+ServletProcess.getRequestParameter("delIds").replace(";","")+")",ServletProcess.getSetSessionAttribute("\"result\"", "\"删除成功\""),ServletProcess.getSetSessionAttribute("\"result\"", "\"删除失败\"")),inTableName,jspFolder);
	inServletContent+=ServletProcess.getEditString(ServletProcess.forServletEditParReg+Symbol.enterSymbol+ServletProcess.getDAOProcessForAddOrEdit("new "+Symbol.getStringFirstUpperCase(inTableName)+"DAO().edit("+BeanProcess.getNewObjectForServlet(inTableName,BeanProcess.editNewObjectInParmForServlet)+")",ServletProcess.getSetSessionAttribute("\"result\"", "\"修改成功\""),ServletProcess.getSetSessionAttribute("\"result\"", "\"修改失败\"")),inTableName,jspFolder);
	inServletContent+=ServletProcess.getDAOProcessForList();
	inServletContent+=ServletProcess.getDAOProcessForListById(inTableName,primaryKey,jspFolder);
	inServletContent+=ServletProcess.getShowAddString("",inTableName,jspFolder);
	servletAll=("".equals(request.getParameter("servletPackage"))?"":ClassProcess.getPackage(request.getParameter("servletPackage")))+("".equals(request.getParameter("beanPackage"))?"":"import "+request.getParameter("beanPackage")+"."+Symbol.getStringFirstUpperCase(inTableName)+";")+Symbol.enterSymbol+("".equals(request.getParameter("daoPackage"))?"":"import "+request.getParameter("daoPackage")+".*;")+Symbol.enterSymbol+ServletProcess.getImportInfo()+ServletProcess.getServlet(inTableName,ServletProcess.getProcessRequest(inServletContent)+ServletProcess.getGoListString(inTableName,jspFolder));
	FileOperate.delete(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"Servlet.java");
	FileOperate.newFile(downloadPath+Symbol.getStringFirstUpperCase(inTableName)+"Servlet.java",servletAll,"utf-8");
	session.setAttribute("servlet",Symbol.getStringFirstUpperCase(inTableName)+"Servlet.java");
	response.sendRedirect("TableColumnResult.jsp");
%>